package com.chinaunicom.club.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.chinaunicom.club.dao.NetMapper;
import com.chinaunicom.club.dto.NetDto;
import com.chinaunicom.club.model.Net;
import com.chinaunicom.club.service.INet;

@Service
public class NetImpl implements INet {
	
	@Resource
	private NetMapper dao;

	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return dao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Net record) {
		// TODO Auto-generated method stub
		return dao.insert(record);
	}

	@Override
	public int insertSelective(Net record) {
		// TODO Auto-generated method stub
		return dao.insertSelective(record);
	}

	@Override
	public Net selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return dao.selectByPrimaryKey(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Net record) {
		// TODO Auto-generated method stub
		return dao.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(Net record) {
		// TODO Auto-generated method stub
		return dao.updateByPrimaryKey(record);
	}

	@Override
	public List<Net> queryAll(Net net) {
		// TODO Auto-generated method stub
		return dao.queryAll(net);
	}

	@Override
	public int check(int id, int checkStatus) {
		//从数据库中取出该网点ID的信息
		Net net = dao.selectByPrimaryKey(id);
		//根据checkStatus的值，1即审核通过，则checkStatus的值为“审核通过”，cancelStatus的值为“潜在”，isCheck的值为1；
		//0即审核不通过，则checkStatus的值为“审核不通过”，cancelStatus的值为“非潜在”，isCheck的值为1；
		if(checkStatus==1){
			net.setCheckStatus("审核通过");
			net.setCancelStatus("潜在");
			net.setIsCheck(1);
		}else if(checkStatus==0){
			net.setCheckStatus("审核不通过");
			net.setIsCheck(1);
		}
		//将数据更新到数据库中
		return dao.updateByPrimaryKeySelective(net);
	}

	@Override
	public int hiddenById(int id) {
		// TODO Auto-generated method stub
		Net net = new Net();
		net.setId(id);
		net.setIsDel(0);
		return dao.hiddenById(net);
	}

	@Override
	public int count(NetDto net) {
		// TODO Auto-generated method stub
		return dao.count(net);
	}

	@Override
	public List<NetDto> queryNetView(Net net,Integer page,Integer rows) {
		// TODO Auto-generated method stub
		//int start = (page-1)*rows;
		//int end = page*rows;
		Map<String,Object> map = new HashMap<>();
		map.put("net", net);
		//map.put("start", start);
		//map.put("end", end);
		return dao.queryNetView(map);
	}
}
